package com.goldgov.information.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.goldgov.information.dao.ArticleRulesDao;
import com.goldgov.information.dao.CrawlerLogDao;
import com.goldgov.information.service.ArticleRules;
import com.goldgov.information.service.ArticleRulesQuery;
import com.goldgov.information.service.ArticleRulesService;
import com.goldgov.utils.PropertyUtil;
@Service
public class ArticleRulesServiceImpl implements ArticleRulesService {

	@Autowired
	ArticleRulesDao articleRulesDao;
	@Autowired
	CrawlerLogDao crawlerLogDao;

	@Override
	public List<ArticleRules> getArticleRulesList(ArticleRulesQuery query) {
		List<ArticleRules> list=articleRulesDao.getArticleRulesList(query);
		for(ArticleRules bean:list) {
			if(PropertyUtil.objectNotEmpty(bean.getLastOperationDate())) {
			bean.setLastOperationNum(crawlerLogDao.getLastCrawlerLogNum(bean.getRulesID()));
			}
		}
		return  list;
	}

	@Override
	public void updateArticleRules(ArticleRules articleRules) {
		articleRulesDao.updateArticleRules(articleRules);
	}

	@Override
	public void addArticleRules(ArticleRules articleRules) {
		articleRulesDao.addArticleRules(articleRules);
	}

	@Override
	public ArticleRules getArticleRulesByID(String rulesID) {
		return articleRulesDao.getArticleRulesByID(rulesID);
	}
	
	/**
	 * 日爬取量
	 * @param query
	 */
	@Override
	public List<ArticleRules> statisticsRPQL(ArticleRulesQuery query){
		query.setPageSize(-1);
		if("".equals(query.getSearchBeginDate())){
			query.setSearchBeginDate(null);
		}
		if("".equals(query.getSearchEndDate())){
			query.setSearchEndDate(null);
		}
		return articleRulesDao.statisticsRPQL(query);
	}
	/**
	 * 栏目爬取量
	 * @param query
	 */
	@Override
	public List<ArticleRules> statisticsLMPQL(ArticleRulesQuery query){
		query.setPageSize(-1);
		if("".equals(query.getSearchBeginDate())){
			query.setSearchBeginDate(null);
		}
		if("".equals(query.getSearchEndDate())){
			query.setSearchEndDate(null);
		}
		return articleRulesDao.statisticsLMPQL(query);
	}

}
